﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System.Net.Http;
using Water.Model;
using System.Net.Http.Headers;
using System.Collections.Generic;

namespace Water.Rest.UnitTest
{
    [TestClass]
    public class BigValveUnitTest
    {
        string basUrl = "http://localhost:46518/";

        [TestMethod]
        public void GetBigValvesCount()
        {
            string url = basUrl + "GetBigValvesCount";
            var requestJson = JsonConvert.SerializeObject(new BigValve {  InspectionEmp="11" });
            HttpContent httpContent = new StringContent(requestJson);
            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void GetBigValves()
        {
            string url = basUrl + "GetBigValves/1/2";
            BigValve info = new BigValve();
            //info.Ve = new Valve() { LOCATION = "哈哈" };
            var requestJson = JsonConvert.SerializeObject(info);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
            var mr = JsonConvert.DeserializeObject<IList<BigValve>>(responseJson);
        }

        [TestMethod]
        public void AddBigValve()
        {
            string url = basUrl + "AddBigValve";
            BigValve info = new BigValve { EpcNo="01", InspectionDt= DateTime.Now, InspectionEmp="11", PipeNet="aa", ProcessingQk="bb" };
            //mr.Mt = new Meter { EpcNo = "01", METERID = "1" };
            var requestJson = JsonConvert.SerializeObject(info);
            HttpContent httpContent = new StringContent(requestJson);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;
        }

        [TestMethod]
        public void GetMenusForuser()
        {
            string url = "http://localhost:8015/PostMenusForuser/admin";
            var requestJson = JsonConvert.SerializeObject(new Water.Model.MenuTree());
            HttpContent httpContent = new StringContent(requestJson);
            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;

            var mr = JsonConvert.DeserializeObject < IList < Water.Model.MenuTree>> (responseJson);
        }

        [TestMethod]
        public void GetMenusForusera()
        {
            string url = "http://localhost:8015/PostAllMenus/1/20";
            var requestJson = JsonConvert.SerializeObject(new Water.Model.MenuTree());
            HttpContent httpContent = new StringContent(requestJson);
            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var httpClient = new HttpClient();
            var responseJson = httpClient.PostAsync(url, httpContent)
                .Result.Content.ReadAsStringAsync().Result;

            var mr = JsonConvert.DeserializeObject < IList <Water.Model.MenuTree>> (responseJson);
        }
    }
}
